#!/bin/bash
echo "Patching disc 1..."
xdelta3 -d -f -s "Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).bin" disc1.xdelta "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).bin"
echo "Patching disc 2..."
xdelta3 -d -f -s "Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).bin" disc2.xdelta "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).bin"

echo "Adding subtitles to the videos..."
java -jar jpsxdecMOD/jpsxdec.jar -f "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).bin" -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx"
java -jar jpsxdecMOD/jpsxdec.jar -f "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).bin" -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx"

java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 219 -replaceframes subtitles/M00.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 222 -replaceframes subtitles/M01.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 225 -replaceframes subtitles/M02.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 228 -replaceframes subtitles/M04.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 231 -replaceframes subtitles/M05.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 234 -replaceframes subtitles/M06.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 237 -replaceframes subtitles/M07.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 240 -replaceframes subtitles/M08.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 243 -replaceframes subtitles/M09.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 246 -replaceframes subtitles/M10.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 249 -replaceframes subtitles/M11.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 252 -replaceframes subtitles/M12.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 255 -replaceframes subtitles/M13.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 258 -replaceframes subtitles/M14.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx" -i 261 -replaceframes subtitles/M15.STR[0].xml

java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 219 -replaceframes subtitles/M16.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 222 -replaceframes subtitles/M17.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 225 -replaceframes subtitles/M18.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 228 -replaceframes subtitles/M19.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 231 -replaceframes subtitles/M20.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 234 -replaceframes subtitles/M21.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 240 -replaceframes subtitles/M23.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 243 -replaceframes subtitles/M24.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 246 -replaceframes subtitles/M25.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 249 -replaceframes subtitles/M26.STR[0].xml
java -jar jpsxdecMOD/jpsxdec.jar -x "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx" -i 252 -replaceframes subtitles/M27.STR[0].xml

rm "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 1).idx"
rm "[EN 1.0] Animetic Story Game 1 - Card Captor Sakura (Japan) (Disc 2).idx"
rm "index.log"
rm "replace.log"
rm "debug0.log"

clear
echo Patching done!
read -p "Press [Enter] to end."

